﻿using System.Windows.Forms;

namespace hello_accinv_New_
{
    public partial class EditProductForm : Form
    {
        private Database db;
        public string loginUser;

        public EditProductForm()
        {
            InitializeComponent();
            db = new Database();
        }

        private void btnSaveChanges_Click(object sender, System.EventArgs e)
        {
            if (IsValidate())
            {
                db.Update("Product",
                "Name = '" + txtboxName.Text +
                "',UnitPrice = '" + txtboxUnitPrice.Text +
                "',Detail = '" + txtboxMoreDetails.Text + "'",
                "PCode = '" + txtboxPCode.Text + "'");

                db.Insert("ActionLog", "'" + CustomDateTime.GetCurrentDate() + "','" + CustomDateTime.GetCurrentTime() + "','" + loginUser + " edited product " + txtboxName.Text + ".'");

                db.Update("Purchase", "Remark = '" + txtboxRemark.Text + "'", "ProductCode = '" + txtboxPCode.Text + "'");
            }
            else
            {
                MessageBox.Show("Check information", "Error");
            }
        }

        private bool IsValidate()
        {
            bool result = true;
            if (txtboxName.Text == "" && txtboxUnitPrice.Text == "" && txtboxQty.Text == "")
                result = false;
            return result;
        }
    }
}

